#ifndef _DISK_STORAGE_H
#define _DISK_STORAGE_H

#include <functional>
#include <list>
#include <string>
#include "memory_storage.h"
#include "mmap.h"

struct DiskStorageChunk : public StorageChunk {
	MemoryStorageChunk *st_chunk_;
	size_t swap_idx_;
};

class DiskStorage : public IStorage {
	public:

	DiskStorage() = delete;
	DiskStorage(uint64_t size, const std::string& filename);
	~DiskStorage();

	virtual StorageChunk *Alloc(uint64_t size,
	    const std::list<StorageChunk**, FSBAllocator<StorageChunk**>>& currently_unused,
	    std::function<void (StorageChunk**)> delete_func);
	virtual void *Load(StorageChunk *p_st_data);
	virtual void Free(StorageChunk *p_st_data);

	virtual void AssertOk();

	private:

	struct Storage {
		MemoryStorage *pstorage_;
		uint64_t offset_;
		uint64_t size_;
	};
	
	Storage *pstorages_; //LECHSH можно было бы использовать вектор и не париться над ассертами
	int storage_count_;
	int mapped_storage_idx_;

	MMap mapping_;
	
	static const uint64_t MAX_MMAP_SIZE = 1024*1024*1024; // 1Gb
};


#endif // _DISK_STORAGE_H
